Skip to content

0.7.1#271

Merged
Bistard merged 67 commits intomasterfrom
dev
Feb 25, 2025
Merged

0.7.1#271
Bistard merged 67 commits intomasterfrom
dev

Conversation

@Bistard
Copy link
Owner

@Bistard Bistard commented Feb 16, 2025

0.7.1

Breaking Changes

  • Standardized serialization process when saving files.

New Features

  • Editor Extension: blockHandleExtension now supports "add-new".
  • Editor Extension: Added AskAIExtension.
  • New editor input rules: Added support for math block, math inline, bold, italic, and codespan.

Chore

  • Improves the editor's paragraph functionality by simulating empty paragraphs as spaces.
  • Removed file extensions from all plugin file names for simplicity.
  • Abstracted out a view class: EditorPalette.
  • Restored PieceTable in EditorModel as the SSOT (Single Source of Truth).
  • Enhanced EditorViewModel.
  • EditorWidget: Introduced new API type.

Fixed

  • The editor core's program input now behaves the same as keyboard input, propagating events to clients (e.g., plugins).

Checklist

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

dependabot bot and others added 4 commits February 16, 2025 01:57
Bumps [serialize-javascript](https://github.com/yahoo/serialize-javascript) to 6.0.2 and updates ancestor dependency [mocha](https://github.com/mochajs/mocha). These dependencies need to be updated together.


Updates `serialize-javascript` from 6.0.0 to 6.0.2
- [Release notes](https://github.com/yahoo/serialize-javascript/releases)
- [Commits](yahoo/serialize-javascript@v6.0.0...v6.0.2)

Updates `mocha` from 9.2.2 to 11.1.0
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/main/CHANGELOG.md)
- [Commits](mochajs/mocha@v9.2.2...v11.1.0)

---
updated-dependencies:
- dependency-name: serialize-javascript
  dependency-type: indirect
- dependency-name: mocha
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
…b3ba2ceb

Bump serialize-javascript and mocha
@Bistard Bistard self-assigned this Feb 16, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 16, 2025

Reviewer's Guide by Sourcery

This pull request introduces significant changes to the editor, including a new text buffer implementation, snippet rules, and UI enhancements. The EditorModel now uses a PieceTable for text storage, and the build process has been updated to tokenize the buffer. The EditorSnippetExtension handles text input and snippet rules, replacing the previous input rule system. The CodeBlock node has been simplified, and the EditorWidget has been updated to use the new EditorModel build process and input emulation. Additionally, the pull request includes updates to various node serializers and the introduction of new editor extensions.

Sequence diagram for EditorModel build process

sequenceDiagram
  participant EditorModel
  participant FileService
  participant TextBufferBuilder
  participant MarkdownLexer

  EditorModel->>FileService: readFileStream(source)
  activate FileService
  FileService-->>EditorModel: ReadableStream
  deactivate FileService
  EditorModel->>TextBufferBuilder: receive(data)
  activate TextBufferBuilder
  TextBufferBuilder-->>EditorModel: IPieceTable
  deactivate TextBufferBuilder
  EditorModel->>MarkdownLexer: lex(buffer.getRawContent())
  activate MarkdownLexer
  MarkdownLexer-->>EditorModel: EditorToken[]
  deactivate MarkdownLexer
  EditorModel-->>EditorModel: { tokens: EditorToken[] }
Loading

Sequence diagram for handling text input in EditorSnippetExtension

sequenceDiagram
  participant EditorSnippetExtension
  participant SnippetRule
  participant ProseMirror

  EditorSnippetExtension->>EditorSnippetExtension: __handleTextInput(view, from, to, text)
  loop for each rule
    EditorSnippetExtension->>SnippetRule: onMatch(state, match, start, end)
    activate SnippetRule
    alt Match found
      SnippetRule->>ProseMirror: tr.insertText(insert, start, end)
      SnippetRule-->>EditorSnippetExtension: tr
    else No match
      SnippetRule-->>EditorSnippetExtension: null
    end
    deactivate SnippetRule
    alt tr is not null
      EditorSnippetExtension->>ProseMirror: dispatch(tr)
    end
  end
Loading

File-Level Changes

Change Details Files
Refactors the EditorModel to use a PieceTable for text storage and introduces a new build process that tokenizes the buffer.
  • Removes ProseMirror related fields and events.
  • Adds IPieceTable to store text.
  • Updates the build method to read file content, build a text buffer, and tokenize it.
  • Implements methods to get content, lines, and character codes from the text buffer.
  • Removes the dependency on IInstantiationService.
  • Removes the __readFileRaw method.
  • Adds the __buildTextBuffer method to read the file stream and build the PieceTable.
  • Adds the __tokenizeBuffer method to tokenize the buffer content.
  • Removes methods related to document nodes.
  • Removes the __tokenizeAndParse method.
  • Removes the __onDidStateChange method.
src/editor/model/editorModel.ts
Introduces a new EditorSnippetExtension to handle text input and snippet rules.
  • Creates EditorSnippetExtension and SnippetRule classes.
  • Defines SnippetReplacement types for string, mark, and node replacements.
  • Adds methods to register, unregister, and retrieve snippet rules.
  • Handles text input and enter key presses to match and apply snippet rules.
  • Adds EditorSnippetExtension to EditorExtensionIDs.
  • Removes EditorInputRuleExtension and IEditorInputRuleExtension.
  • Removes InputRule and IInputRule.
  • Removes registerDefaultInputRules.
  • Removes inputRuleExtension.ts and editorInputRules.ts.
src/editor/contrib/snippet/snippet.ts
Updates the CodeBlock node to use triple backticks for fences and simplifies fence status resolution.
  • Removes CodeBlockFenceType enum.
  • Removes fence-related attributes from CodeBlockAttrs.
  • Updates the toDOM method to use triple backticks.
  • Updates the serializer method to use triple backticks and removes fence type logic.
  • Removes the __resolveFenceStatus function.
src/editor/model/documentNode/node/codeBlock/codeBlock.ts
Updates the EditorWidget to use the new EditorModel build process and introduces input emulation.
  • Updates the open method to use the new EditorModel build process.
  • Adds type and keydown methods to interact with the editor view.
  • Adds IEditorInputEmulator interface.
  • Updates the __createView method to pass the IEditorInputEmulator to the EditorView.
  • Removes the onDidStateChange event.
  • Removes the insertAt and deleteAt methods.
src/editor/editorWidget.ts
Refactors the EditorViewModel to handle model building and view content changes.
  • Removes ProseMirror related events.
  • Adds the build method to create the initial editor state.
  • Adds the updateViewChange method to update the model state based on view changes.
  • Removes the onDidViewContentChange method.
  • Adds methods to get registered document nodes.
  • Adds the __parse method to parse tokens into a ProseNode.
  • Adds the __registerListeners method to register token mapping.
src/editor/viewModel/editorViewModel.ts
Updates the RichTextView to use the new input emulation and simplifies the typing logic.
  • Adds IEditorInputEmulator field.
  • Adds type and keydown methods to simulate user input.
  • Removes the __registerEventToModel method.
  • Removes the __registerEventFromModel method.
src/editor/view/richTextView.ts
Updates the Blockquote node serializer to use wrapBlock.
  • Removes the __getDelimitersFromRaw method.
  • Updates the serializer method to use wrapBlock.
src/editor/model/documentNode/node/blockquote.ts
Updates the List node to support start attribute as a number.
  • Updates the ListAttrs type to support start as a number.
  • Updates the parseFromToken method to handle start as a number.
  • Updates the serializer method to handle start as a number.
src/editor/model/documentNode/node/list.ts
Updates the Paragraph node serializer to simulate empty paragraphs as spaces.
  • Updates the serializer method to write a newline character for empty paragraphs.
src/editor/model/documentNode/node/paragraph.ts
Updates the EditorDragAndDropExtension to EditorDragAndDrop.
  • Renames EditorDragAndDropExtension to EditorDragAndDrop.
  • Renames dragAndDropExtension.ts to dragAndDrop.ts.
src/editor/contrib/dragAndDrop/dragAndDrop.ts
Updates the EditorBlockHandleExtension to EditorBlockHandle.
  • Renames EditorBlockHandleExtension to EditorBlockHandle.
  • Renames blockHandleExtension.ts to blockHandle.ts.
src/editor/contrib/blockHandle/blockHandle.ts
Updates the EditorBlockPlaceHolderExtension to EditorBlockPlaceHolder.
  • Renames EditorBlockPlaceHolderExtension to EditorBlockPlaceHolder.
  • Renames blockPlaceHolderExtension.ts to blockPlaceHolder.ts.
src/editor/contrib/blockPlaceHolder/blockPlaceHolder.ts
Updates the EditorSlashCommandExtension to EditorSlashCommand.
  • Renames EditorSlashCommandExtension to EditorSlashCommand.
  • Renames slashCommandExtension.ts to slashCommand.ts.
src/editor/contrib/slashCommand/slashCommand.ts
Updates the EditorCommandExtension to EditorCommand.
  • Renames EditorCommandExtension to EditorCommand.
  • Renames commandExtension.ts to command.ts.
src/editor/contrib/command/command.ts
Updates the EditorAutoSaveExtension to EditorAutoSave.
  • Renames EditorAutoSaveExtension to EditorAutoSave.
  • Renames autoSaveExtension.ts to autoSave.ts.
src/editor/contrib/autoSave.ts
Adds EditorAskAIExtension.
  • Adds EditorAskAIExtension to EditorExtensionIDs.
  • Adds EditorAskAIExtension to builtInExtensionList.ts.
src/editor/contrib/askAI/askAI.ts
Updates the EditorView to pass the IEditorInputEmulator to the RichTextView.
  • Adds IEditorInputEmulator field.
  • Updates the __createView method to pass the IEditorInputEmulator to the RichTextView.
src/editor/view/editorView.ts
Updates the DocumentNodeProvider to remove Space node.
  • Removes Space node from register method.
src/editor/model/documentNode/documentNodeProvider.ts
Updates the MathInline node to be draggable, selectable, and atom.
  • Adds draggable, selectable, and atom to MathInline node schema.
src/editor/model/documentNode/mark/mathInline.ts
Updates the MathBlock node to be draggable, selectable, and atom.
  • Adds draggable, selectable, and atom to MathBlock node schema.
src/editor/model/documentNode/node/mathBlock.ts
Updates the PriorityEmitter to be safe disposable.
  • Updates the __constructContainer method to be safe disposable.
src/base/common/event.ts
Updates the EditorPalette to be safe disposable.
  • Updates the EditorPalette to be safe disposable.
src/editor/view/widget/palette/palette.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Bistard - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding dispose to the IListenerContainer interface to ensure consistent resource management.
  • It looks like you're adding dispose methods to clean up resources - ensure that these are called when the emitter is no longer needed to prevent memory leaks.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Bistard
Copy link
Owner Author

Bistard commented Feb 25, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Bistard - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider extracting the editor extensions and their configurations into a separate module for better organization and maintainability.
  • The removal of insertAt and deleteAt from the IEditorWidget interface might affect existing code that relies on these methods.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Bistard Bistard merged commit b177bc6 into master Feb 25, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant